// src/stores/counterStore.js
import { defineStore } from 'pinia'
import Taro from '@tarojs/taro'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
  }),
  actions: {
    increment() {
      this.count++
    },
    decrement() {
      this.count--
    },
  },
  // persist: true, // ✅ 开启持久化
  persist: {
    key: 'counter',
    storage: {
      getItem: Taro.getStorageSync,
      setItem: Taro.setStorageSync,
    },
    serializer: {
      serialize: JSON.stringify,
      deserialize: JSON.parse,
    },
    debug: process.env.NODE_ENV !== 'production',
  },
})
